# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lame
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.99.5
pkgrel=4
pkgdesc="A high quality MPEG Audio Layer III (MP3) encoder (mingw-w64)"
arch=('any')
url="http://lame.sourceforge.net/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-mpg123"
             "${MINGW_PACKAGE_PREFIX}-nasm"
             "${MINGW_PACKAGE_PREFIX}-ncurses"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libiconv")
options=('strip' 'staticlibs')
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-fix-cr-for-awk-in-configure.mingw.patch
        0002-07-field-width-fix.all.patch
        0003-parallel-builds-fix.all.patch
        0004-disable-wrong-xmmintrin-detection.all.patch
        0005-no-gtk.all.patch)
sha256sums=('24346b4158e4af3bd9f2e194bb23eb473c75fb7377011523353196b19b9a23ff'
            'e71a71493cf982818b28b27b890856775ed97859d55d2a23f4b59de821850e75'
            'd3ba595816761706d1e5dcf432f0b3ad8c9c6b37584032e21bf24c89e4fd0fc8'
            '727a5baff860c6b551564228d087cc30cd0f347d1d0f1ad416405189798aca05'
            '720aeda3b4094c75bbb80fbc1e4a671a4549a08ecc9ab96d281e97aa7bdbb419'
            'cd3c8807de5b435b8e97200e369e7e8f93f7fc0eba7d44b393ede925e42d3b00')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0001-fix-cr-for-awk-in-configure.mingw.patch
  patch -p1 -i ${srcdir}/0002-07-field-width-fix.all.patch
  patch -p1 -i ${srcdir}/0003-parallel-builds-fix.all.patch
  patch -p1 -i ${srcdir}/0004-disable-wrong-xmmintrin-detection.all.patch
  patch -p1 -i ${srcdir}/0005-no-gtk.all.patch

  autoreconf -fi
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-nasm \
    --enable-shared \
    --enable-static
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
